<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>主菜单</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" href="css/semantic.css" />
		<link rel="stylesheet" href="css/mui.picker.css" />
		<link rel="stylesheet" href="css/mui.poppicker.css" />
		<link rel="stylesheet" type="text/css" href="css/font-awesome.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/startinventory.css" />-->

	</head>
	<style type="text/css">
		.mui-plus .plus {
			display: inline;
		}
		
		.mui-card {
			background-image: linear-gradient(to bottom, #A4D3EE, white);
			background-color: #007AFF;
		}
		
		.plus {
			display: none;
		}
		
		#topPopover {
			position: fixed;
			top: 16px;
			right: 6px;
		}
		
		#topPopover .mui-popover-arrow {
			left: auto;
			right: 6px;
		}
		
		span.mui-icon {
			font-size: 14px;
			color: #007aff;
			margin-left: -15px;
			padding-right: 10px;
		}
		
		.mui-popover {
			height: 300px;
		}
		
		.mui-content {
			padding: 10px;
		}
		
		#open_inventory_btn {
			position: fixed;
			top: 20%;
			left: 0px;
			right: 0px;
			margin: auto;
		}
		
		#open_inventory_rfid_btn {
			position: fixed;
			bottom: 20%;
			left: 0px;
			right: 0px;
			margin: auto;
		}
		.m-btn {
			position: fixed;
			left: 0px;
			right: 0px;
			bottom: 10px;
			margin: auto;
			text-align: center;
			line-height: 30px;
			border-radius: 25px;
			width: 35%;
			height: 30px;
			background-color: whitesmoke;
			opacity: 0.7;
			border: 1px solid #B5B5B5;
		}
		
		.m-complete {
			padding-right: 20px;
			padding-left: 20px;
			font-size: 20px;
		}
		
		.mui-row {
			height: 28px;
		}
		
		.m-table {
			margin: 9px 0px 0px 14px;
		}
		.content{
			margin-top: 12%;
		}
	</style>

	<body>

		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">盘点资产</h1>
		</header>
		<div id="showUserPicker">
			<img src="img/nfc-logo.jpg" alt="" class="ui  small image" id="open_inventory_btn">
			<div id='userResult' class="ui-alert"></div>
		</div>
		<div id="showRfid">
			<img src="img/OIP.jpg" alt="" class="ui  small image" id="open_inventory_rfid_btn">
			<div id='userResultRfid' class="ui-alert"></div>
		</div>
		
		<div class="content" id="span_content">
			
		</div>

		</div>
		<div id="inventory_bottom_menu" class="inventory_bottom_menu mui-hidden">
			<label class="m-btn">
				<span class="m-complete" id="complete"><i class="fa fa-hand-peace-o "></i></span>
				<a href="#bottomPopover"><span class="m-complete"><i class="fa fa-pencil-square-o"></i></span></a>
			</label>
		</div>
		<!--选择框组件-->
		<div id="bottomPopover" class="mui-popover mui-popover-bottom">
			<div class="mui-popover-arrow"></div>
			<div class="mui-scroll-wrapper">
				<div class="mui-scroll">
					<ul class="mui-table-view">
						<li class="mui-table-view-cell">
							<a href="#"></a>
							<label class="mui-h3">手动盘点</label> （二选一）
							<form class="mui-input-group">
								<div class="mui-input-row">
									<label>资产编号</label>
									<input type="text" name="handel_assetNum" id="handel_assetNum" class="mui-input-clear" placeholder="手动输入">
								</div>
								<div class="mui-input-row mui-plus-visible">
									<label>资产编号</label>
									<input type="text" class="mui-input-speech mui-input-clear" id="handel_assetNum_voice" placeholder="语音输入">
								</div>
								<div class="mui-button-row">
									<button class="mui-btn mui-btn-primary" type="button" onclick="handelinventory()">确认</button>&nbsp;&nbsp;
								</div>
							</form>
						</li>

					</ul>
				</div>
			</div>

		</div>
		<audio id="audio">
  		<source src="audio/success.wav" type="audio/wav">
		您的浏览器不支持 audio 元素。
		</audio>
	</body>

</html>
<script type="text/javascript" src="js/mui.js"></script>
<script src="js/addressinitialization.js"></script>
<script type="text/javascript" src="js/mui.picker.js"></script>
<script type="text/javascript" src="js/mui.poppicker.js"></script>

<script type="text/javascript">
	var select_active_store = null;

	// 选择存放地
	(function($, doc) {
		$.ready(function() {
			var store_menu = new Array();
			mui.ajax(IP + '/ias/AndroidInputAsset/listDepartStore', {
				type: "GET",
				dataType: 'json',
				success: function(response) {
					var store = response.data;
					var result = response.result;

					if(store == "空") {
						mui.confirm('数据错误，请检查登陆状态', '提示', "是", function(e) {
							if(e.index == 0) {
								window.location = "startinventory.html";
							} else {; //
							}
						});
					} else {
						for(var i = 0; i < store.length; i++) {
							store_menu[i] = {
								text: store[i]
							};
						}
						//普通示例
						var userPicker = new $.PopPicker();
						userPicker.setData(store_menu);
						var showUserPickerButton = doc.getElementById('showUserPicker');
						// 选择NFC
						var userResult = doc.getElementById('userResult');
						showUserPickerButton.addEventListener('tap', function(event) {
							console.log(result);
							if(result == "error") {
								console.log(response.msg);
								var msg = response.msg;
								mui.confirm(msg, '提示', "是", function(e) {
									if(e.index == 0) {
										window.location = "startinventory_back.html";
									} else {; //
									}
								});
							} else {
								userPicker.show(function(items) {
									//userResult.innerText = JSON.stringify(items[0]);
									//返回 false 可以阻止选择框的关闭
									//return false;
									console.log("选择了NFC:"+items[0].text)
									select_active_store = items[0].text;
									document.getElementById('showUserPicker').classList.add('mui-hidden');
									document.getElementById('showRfid').classList.add('mui-hidden');
									document.getElementById('inventory_bottom_menu').classList.remove('mui-hidden');
									readData();
								});
							}
						}, false);
						// 选择RFID
						var RfidPicker = new $.PopPicker();
						RfidPicker.setData(store_menu);
						var rfidButton = doc.getElementById('showRfid');
						var userResultRfid = doc.getElementById('userResultRfid');
						rfidButton.addEventListener('tap', function(event) {
							console.log(result);
							if(result == "error") {
								console.log(response.msg);
								var msg = response.msg;
								mui.confirm(msg, '提示', "是", function(e) {
									if(e.index === 0) {
										window.location = "startinventory.html";
									} else {; //
									console.log("else")
									}
								});
							} else {
								userPicker.show(function(items) {
									//userResult.innerText = JSON.stringify(items[0]);
									//返回 false 可以阻止选择框的关闭
									//return false;
									console.log("选择了RFID:"+items[0].text)
									select_active_store = items[0].text;
									document.getElementById('showRfid').classList.add('mui-hidden');
									document.getElementById('inventory_bottom_menu').classList.remove('mui-hidden');
									// readData();
									window.location = 'rfidScanIndex.html?select_active_store='+select_active_store;
								});
							}
						}, false);
					}
				},
				error: function(xhr, textStatus, errorThrown) {
					mui.alert("数据错误，请检查登陆状态");
				}
			})

		});
	})(mui, document);

	mui.init();
	/*window.onload = function() {
		start(); //开始扫描
		complete_but(); //完成扫描
	}*/
	// 预加载详情页
	mui.plusReady(function() {
		start(); //开始扫描
		complete_but(); //完成扫描
		mui.preload({
			url: 'complete_sub.html',
			id: 'complete_sub.html'
		});
		sub_page = plus.webview.getWebviewById('complete_sub.html');
	})

	// 监听跳转详情页
	function tap_sub_event() {
		mui(".mui-card").on('tap', '.mui-card-header', function() {
			var title = this.getAttribute("title");
			var id = this.getAttribute("id");
			mui.fire(sub_page, 'get_detail', {
				title_: title,
				id_: id
			});
		})
	}

	//开始扫描
	function start() {
		//mui.toast("开始扫描");
		//将扫描存放地存入域中
		var storeName = select_active_store;
		mui.ajax(IP + '/ias/AndroidInputAsset/setStoreName', {
			data: {
				storeName: storeName
			},
			type: 'post',
			dataType: 'json',
			timeout: 10000,
			headers: {
				'Content-Type': 'application/json'
			},
			error: function(xhr, type, errorThrown) {
				mui.toast("请求失败，请检查登陆状态");
			}
		});

	}

	//手动盘点
	function handelinventory() {
		var storeName = select_active_store;
		var assetNum = "";
		if(mui("#handel_assetNum_voice")[0].value===""){
			assetNum = mui("#handel_assetNum")[0].value;
		}
		if(mui("#handel_assetNum")[0].value===""){
			assetNum = mui("#handel_assetNum_voice")[0].value;
			console.log(mui("#handel_assetNum_voice")[0].value);
		}
		
		var Android_URL = IP + '/ias/AndroidInputAsset/InventoryProcess';
		
		if(assetNum == "") {
			mui.alert("请输入资产编号");
		} else {
			mui.ajax(Android_URL, {
				data: {
					assetNum: assetNum,
					storeName: storeName
				},
				type: 'post',
				dataType: 'json',
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(response) {
					if(response.result == 'error') {
						mui.alert(response.msg);
					} else {
						/*获取后台数据*/
						var asset = response.data;
						if(asset.assetNum != null) {
							var assetNum = asset.assetNum; //资产编号
							var assetName = asset.assetName; //资产名称
							var inventoryStore = asset.inventoryStore; //存放地
							var inventoryDepart = asset.inventoryDepart; //部门
							var inventoryBatch = asset.inventoryBatch; //批次号
							var inventoryDate = asset.inventoryDate; //盘点时间
							var inventoryStatus = asset.inventoryStatus; //盘点状态
							var inventoryspanAdrr = asset.inventoryspanAdrr; //扫描地
							var admin = "陈少磊";
							/*是否已存在信息框*/
							var msg_div = document.getElementById(assetNum);
							if(msg_div == null) {
								/*动态添加信息框*/
								var parent = document.getElementById("span_content");
								var m_card = document.createElement('div');
								m_card.className = "mui-card";
								// 卡片header
								var m_card_header = document.createElement('div');
								m_card_header.className = "mui-card-header";
								m_card_header.title = assetName;
								m_card_header.id = assetNum;
								m_card_header.innerText = assetName;
								var m_card_header_span = document.createElement('span');
								m_card_header_span.className = "mui-right";
								var m_card_header_a = document.createElement('a');
								m_card_header_a.className = "mui-navigate-right";
								/*m_card_header_a.title = assetName;
								m_card_header_a.id = assetNum;*/
								m_card_header_span.appendChild(m_card_header_a);
								m_card_header.appendChild(m_card_header_span);

								//卡片content
								var m_card_content = document.createElement('div');
								m_card_content.className = "mui-card-content";
								var m_table = document.createElement('div');
								m_table.className = "m-table";

								// row1
								var m_c_row_1 = document.createElement('div');
								m_c_row_1.className = "mui-row";
								var m_c_row_1_col_1 = document.createElement('div');
								m_c_row_1_col_1.className = "mui-col-xs-8";
								var m_c_asset_id = document.createElement('h5');
								m_c_asset_id.className = "mui-ellipsis";
								m_c_asset_id.innerText = "资产编号";
								var m_c_asset_id_span = document.createElement('span');
								m_c_asset_id_span.innerText = assetNum;
								m_c_asset_id.appendChild(m_c_asset_id_span);
								m_c_row_1_col_1.appendChild(m_c_asset_id);
								var m_c_row_1_col_2 = document.createElement('div');
								m_c_row_1_col_2.className = "mui-col-xs-4";
								var m_c_asset_status = document.createElement('h5');
								m_c_asset_status.classList.add('mui-ellipsis', 'm-status');
								m_c_asset_status.innerText = inventoryStatus;
								m_c_row_1_col_2.appendChild(m_c_asset_status);
								m_c_row_1.appendChild(m_c_row_1_col_1);
								m_c_row_1.appendChild(m_c_row_1_col_2);

								//row2
								var m_c_row_2 = document.createElement('div');
								m_c_row_2.className = "mui-row";
								var m_c_row_2_col_1 = document.createElement('div');
								m_c_row_2_col_1.className = "mui-col-xs-6";
								var m_c_asset_store = document.createElement('p');
								m_c_asset_store.className = "mui-ellipsis";
								m_c_asset_store.innerText = "存放地：";
								var m_c_asset_store_span = document.createElement('span');
								m_c_asset_store_span.innerText = inventoryStore;
								m_c_asset_store.appendChild(m_c_asset_store_span);
								m_c_row_2_col_1.appendChild(m_c_asset_store);
								var m_c_row_2_col_2 = document.createElement('div');
								m_c_row_2_col_2.className = "mui-col-xs-6";
								var m_c_asset_spanaddr = document.createElement('p');
								m_c_asset_spanaddr.className = "mui-ellipsis";
								m_c_asset_spanaddr.innerText = "扫描地：";
								var m_c_asset_spanadder_span = document.createElement('span');
								m_c_asset_spanadder_span.innerText = inventoryspanAdrr;
								m_c_asset_spanaddr.appendChild(m_c_asset_spanadder_span);
								m_c_row_2_col_2.appendChild(m_c_asset_spanaddr);
								m_c_row_2.appendChild(m_c_row_2_col_1);
								m_c_row_2.appendChild(m_c_row_2_col_2);
								//row3
								var m_c_row_3 = document.createElement('div');
								m_c_row_3.className = "mui-row";
								var m_c_row_3_col_1 = document.createElement('div');
								m_c_row_3_col_1.className = "mui-col-xs-6";
								var m_c_time = document.createElement('p');
								var m_c_time_span = document.createElement('span');
								m_c_time_span.innerText = inventoryDate;
								m_c_time.appendChild(m_c_time_span);
								m_c_row_3_col_1.appendChild(m_c_time);
								var m_c_row_3_col_2 = document.createElement('div');
								m_c_row_3_col_2.className = "mui-col-xs-6";
								var m_c_admin = document.createElement('p');
								m_c_admin.className = "mui-ellipsis";
								m_c_admin.innerText = "盘点人：";
								var m_c_admin_span = document.createElement('span');
								m_c_admin_span.innerText = admin;
								m_c_admin.appendChild(m_c_admin_span);
								m_c_row_3_col_2.appendChild(m_c_admin);
								m_c_row_3.appendChild(m_c_row_3_col_1);
								m_c_row_3.appendChild(m_c_row_3_col_2);

								m_table.appendChild(m_c_row_1);
								m_table.appendChild(m_c_row_2);
								m_table.appendChild(m_c_row_3);
								m_card_content.appendChild(m_table);
								m_card.appendChild(m_card_header);
								m_card.appendChild(m_card_content);
								parent.insertBefore(m_card, parent.firstElementChild);

								mui.toast("手动盘点成功");
								tap_sub_event();
							} else {
								mui.toast("已盘点");
							}
						} else {
							mui.toast("不存在此资产");
						}
					}

				},
				error: function(xhr, textStatus, errorThrown) {
					mui.toast("数据错误，请检查登陆状态");
				}
			});
		}
	}

	//完成扫描
	function complete_but() {
		document.getElementById("complete").addEventListener("tap", function(e) {
			e.detail.gesture.preventDefault();
			var btnArray = ['否', '是'];
			mui.confirm("确认完成扫描？", "提示", btnArray, function(e) {
				if(e.index == 1) {
					closereadData();
					window.location = "startinventory.html";
				} else {; //否
				}
			})
		})
	}

	//主页返回键处理
	mui.back = function() {
		window.location = "startinventory.html";
	}
	//nfc功能
	var NfcAdapter;
	// 密钥
	var key_A = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00];
	// 检测NFC标签
	function listenNFCStatus() {
		try {
			var main = plus.android.runtimeMainActivity();
			// 加载安卓sdk中用于启动活动的Intent;这是想要要执行操作抽象描述的数据结构
			var Intent = plus.android.importClass('android.content.Intent');
			// 创建窗口
			var Activity = plus.android.importClass('android.app.Activity');
			// 描述目标操作和意图
			var PendingIntent = plus.android.importClass('android.app.PendingIntent');
			// 过滤器
			var IntentFilter = plus.android.importClass('android.content.IntentFilter');
			// 适配器
			NfcAdapter = plus.android.importClass('android.nfc.NfcAdapter');
			// 获取手机默认的适配器
			var nfcAdapter = NfcAdapter.getDefaultAdapter(main);
			if(nfcAdapter == null) {
				mui.toast("设备不支持NFC！");
				return;
			}
			if(!nfcAdapter.isEnabled()) {
				alert("请在系统设置中先启用NFC功能！");
				return;
			}
			// 创建意图对象
			var intent = new Intent(main, main.getClass());
			// 为意图添加附加标志  该活动以运行则不启动该活动
			intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
			// 检索并启动新活动
			var pendingIntent = PendingIntent.getActivity(main, 0, intent, 0);
			// 为活动匹配一个过滤器
			var ndef = new IntentFilter("android.nfc.action.TECH_DISCOVERED");
			ndef.addDataType("*/*");
			var intentFiltersArray = [ndef];
			// 所有支持的标签技术
			var techListsArray = [
				["android.nfc.tech.IsoDep"],
				["android.nfc.tech.NfcA"],
				["android.nfc.tech.NfcB"],
				["android.nfc.tech.NfcF"],
				["android.nfc.tech.Nfcf"],
				["android.nfc.tech.NfcV"],
				["android.nfc.tech.NdefFormatable"],
				["android.nfc.tech.MifareClassic"],
				["android.nfc.tech.MifareUltralight"]
			];
			// 监听获取intent总信息
			document.addEventListener("newintent",
				function() {
					console.error('newintent');
					setTimeout(handle_nfc_data1, 1000);
				}, false);
			document.addEventListener("pause", function(e) {
				if(nfcAdapter) {
					// 禁用对给定活动的前台分派
					nfcAdapter.disableForegroundDispatch(main);
					console.log('pause');
				}
			}, false);
			document.addEventListener("resume", function(e) {
				if(nfcAdapter) {
					console.log('resume');
					// 启用对给定活动的前台分派 参数1.要调度的活动 2.等待开始发送的意图3.过滤器4.所能匹配的标签类型列表
					nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
				}
			}, false);
			nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
		} catch(e) {
			console.error(e);
		}
	}
	// 处理NFC标签数据
	function handle_nfc_data1() {
		// 获取主应用
		var main = plus.android.runtimeMainActivity();
		// 获取正在请求的intent
		var intent = main.getIntent();
		console.log("action type:" + intent.getAction());
		if("android.nfc.action.TECH_DISCOVERED" == intent.getAction()) {
			if(readyWriteData) {
				__write(intent);
				readyWriteData = false;
			} else if(readyRead) {

				__read(intent);
			}
		} else {
			console.log("action 失败");
		}
	}
    // 开启NFC读数据
	function readData() {
		readyRead = true;
	}
	// 关闭NFC读数据
	function closereadData() {
		readyRead = false;
	}

	// 从nfc标签中读取的数据
	var readDataResult = "";
	var a = "";
    // 读取NFC标签数据
	function __read(intent) {
		// 判断密钥是否正确
		var isAuth = false;
		try {
			var content = "";
			//waiting.setTitle('请勿移开标签\n正在读取数据...');
			plus.android.importClass("android.nfc.Tag");
			var MifareClassic = plus.android.importClass("android.nfc.tech.MifareClassic");
			var tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
			var tagID = tag.getId();
			console.log("Tag的ID为：" + bytesToHexString(tagID));
			// 实例化一个MifareClassic对象
			var mfc = MifareClassic.get(tag);
			
			if(mfc != null) {
				try {
					mfc.connect();
					// 获取扇区数量
					var nSecont = mfc.getSectorCount();
					
					//只读取第一个扇区的1号块中数据
					isAuth = mfc.authenticateSectorWithKeyA(0, key_A);
					console.log(isAuth+"实例化一个MifareClassic对象"+key_A)
					if(isAuth) {
						var nBlock = mfc.getBlockCountInSector(0);
						var data = mfc.readBlock(1);
						var result = bytesToHexString(data);

						//var a="";
						//console.log("2");
						//**转为16进制*/
						//								mui.ajax(IP+'/ias/PCHanderTag/handleReadData',{
						//									data:{datastr :result},
						//									type: 'post',
						//									dataType: 'json',
						//									headers:{'Content-Type':'application/json'},
						//									success: function(response) {
						//										console.log("成功");
						//										//a=response.data;
						//										console.log(response);
						//									},
						//									error: function(xhr, textStatus, errorThrown) {
						//										mui.toast("数据错误，请检查登陆状态");
						//									}
						//								})

						//mui.alert(a);
						//content = readDataResult;
						readDataResult = result;
						var truedata = "";
						if(readDataResult != null) {
							
							var data = {
								datastr: result
							}
							//处理读取数据的格式与后台一致
							mui.ajax(IP + '/ias/PCHanderTag/handleReadData', {
								data: data,
								type: 'post',
								dataType: 'json',
								//headers:{'Content-Type':'application/json'},
								success: function(response) {
									truedata = response.data;
									console.log("处理后的数据1"+truedata);
									getAssetInfo(truedata,select_active_store);
									
								},
								error: function(xhr, textStatus, errorThrown) {
									
									mui.alert("数据错误，请检查登陆状态");
								}
							})
							console.log("处理后的数据"+truedata);
						} else {
							mui.toast("扫描失败");
						}
						console.log(readDataResult);
					}
				} catch(e) {
					mui.toast("读取失败，请重新扫描");
					mfc.close();
				}
				mfc.close();
			} else {
				console.log("skySeraph, your Tag is not MifareClassic");
			}
		} catch(e) {
			alert(e);
		}
		return readDataResult;
	}

	// 获取NFC扫描的资产信息
	function getAssetInfo(assetNum,storeName){
		//根据扫描所得资产编号获取资产信息
		mui.ajax(IP + '/ias/AndroidInputAsset/InventoryProcess', {
			data: {
				assetNum: assetNum,
				storeName: storeName
			},
			type: 'post',
			dataType: 'json',
			headers: {
				'Content-Type': 'application/json'
			},
			success: function(response) {
				if(response.result == 'error') {
					mui.alert(response.msg);
				} else {
					/*获取后台数据*/
					
					var asset = response.data;
					console.log(asset);
					if(asset.assetNum != null) {
						var assetNum = asset.assetNum; //资产编号
						var assetName = asset.assetName; //资产名称
						var inventoryStore = asset.inventoryStore; //存放地
						var inventoryDepart = asset.inventoryDepart; //部门
						var inventoryBatch = asset.inventoryBatch; //批次号
						var inventoryDate = asset.inventoryDate; //盘点时间
						var inventoryStatus = asset.inventoryStatus; //盘点状态
						var inventoryspanAdrr = asset.inventoryspanAdrr; //扫描地
						var admin = "陈少磊";
						/*是否已存在信息框*/
						var msg_div = document.getElementById(assetNum);
						if(msg_div == null) {
							/*动态添加信息框*/
							var parent = document.getElementById("span_content");
							var m_card = document.createElement('div');
							m_card.className = "mui-card";
							// 卡片header
							var m_card_header = document.createElement('div');
							m_card_header.className = "mui-card-header";
							m_card_header.title = assetName;
							m_card_header.id = assetNum;
							m_card_header.innerText = assetName;
							var m_card_header_span = document.createElement('span');
							m_card_header_span.className = "mui-right";
							var m_card_header_a = document.createElement('a');
							m_card_header_a.className = "mui-navigate-right";
							/*m_card_header_a.title = assetName;
							m_card_header_a.id = assetNum;*/
							m_card_header_span.appendChild(m_card_header_a);
							m_card_header.appendChild(m_card_header_span);
	
							//卡片content
							var m_card_content = document.createElement('div');
							m_card_content.className = "mui-card-content";
							var m_table = document.createElement('div');
							m_table.className = "m-table";
	
							// row1
							var m_c_row_1 = document.createElement('div');
							m_c_row_1.className = "mui-row";
							var m_c_row_1_col_1 = document.createElement('div');
							m_c_row_1_col_1.className = "mui-col-xs-8";
							var m_c_asset_id = document.createElement('h5');
							m_c_asset_id.className = "mui-ellipsis";
							m_c_asset_id.innerText = "资产编号";
							var m_c_asset_id_span = document.createElement('span');
							m_c_asset_id_span.innerText = assetNum;
							m_c_asset_id.appendChild(m_c_asset_id_span);
							m_c_row_1_col_1.appendChild(m_c_asset_id);
							var m_c_row_1_col_2 = document.createElement('div');
							m_c_row_1_col_2.className = "mui-col-xs-4";
							var m_c_asset_status = document.createElement('h5');
							m_c_asset_status.classList.add('mui-ellipsis', 'm-status');
							m_c_asset_status.innerText = inventoryStatus;
							m_c_row_1_col_2.appendChild(m_c_asset_status);
							m_c_row_1.appendChild(m_c_row_1_col_1);
							m_c_row_1.appendChild(m_c_row_1_col_2);
	
							//row2
							var m_c_row_2 = document.createElement('div');
							m_c_row_2.className = "mui-row";
							var m_c_row_2_col_1 = document.createElement('div');
							m_c_row_2_col_1.className = "mui-col-xs-6";
							var m_c_asset_store = document.createElement('p');
							m_c_asset_store.className = "mui-ellipsis";
							m_c_asset_store.innerText = "存放地：";
							var m_c_asset_store_span = document.createElement('span');
							m_c_asset_store_span.innerText = inventoryStore;
							m_c_asset_store.appendChild(m_c_asset_store_span);
							m_c_row_2_col_1.appendChild(m_c_asset_store);
							var m_c_row_2_col_2 = document.createElement('div');
							m_c_row_2_col_2.className = "mui-col-xs-6";
							var m_c_asset_spanaddr = document.createElement('p');
							m_c_asset_spanaddr.className = "mui-ellipsis";
							m_c_asset_spanaddr.innerText = "扫描地：";
							var m_c_asset_spanadder_span = document.createElement('span');
							m_c_asset_spanadder_span.innerText = inventoryspanAdrr;
							m_c_asset_spanaddr.appendChild(m_c_asset_spanadder_span);
							m_c_row_2_col_2.appendChild(m_c_asset_spanaddr);
							m_c_row_2.appendChild(m_c_row_2_col_1);
							m_c_row_2.appendChild(m_c_row_2_col_2);
							//row3
							var m_c_row_3 = document.createElement('div');
							m_c_row_3.className = "mui-row";
							var m_c_row_3_col_1 = document.createElement('div');
							m_c_row_3_col_1.className = "mui-col-xs-6";
							var m_c_time = document.createElement('p');
							var m_c_time_span = document.createElement('span');
							m_c_time_span.innerText = inventoryDate;
							m_c_time.appendChild(m_c_time_span);
							m_c_row_3_col_1.appendChild(m_c_time);
							var m_c_row_3_col_2 = document.createElement('div');
							m_c_row_3_col_2.className = "mui-col-xs-6";
							var m_c_admin = document.createElement('p');
							m_c_admin.className = "mui-ellipsis";
							m_c_admin.innerText = "盘点人：";
							var m_c_admin_span = document.createElement('span');
							m_c_admin_span.innerText = admin;
							m_c_admin.appendChild(m_c_admin_span);
							m_c_row_3_col_2.appendChild(m_c_admin);
							m_c_row_3.appendChild(m_c_row_3_col_1);
							m_c_row_3.appendChild(m_c_row_3_col_2);
	
							m_table.appendChild(m_c_row_1);
							m_table.appendChild(m_c_row_2);
							m_table.appendChild(m_c_row_3);
							m_card_content.appendChild(m_table);
							m_card.appendChild(m_card_header);
							m_card.appendChild(m_card_content);
							parent.insertBefore(m_card, parent.firstElementChild);
							audio_success();
							mui.toast("盘点成功");
							tap_sub_event();
						} else {
							mui.toast("已盘点");
						}
					} else {
						mui.toast("不存在此资产");
					}
				}
	
			},
			error: function(xhr, textStatus, errorThrown) {
				mui.toast("数据错误，请检查登陆状态");
			}
		});
	}
	function stringToHex(str) {　　　　
		var val = "";　　　　
		for(var i = 0; i < str.length; i++) {
			if(val == "")　　　　　　　　
				val = str.charCodeAt(i).toString(16);　　　　　　
			else　　　　　　　　
				val += "," + str.charCodeAt(i).toString(16);　　　　
		}　　　　
		return val;　　
	}

	function bytesToHexString(inarray) {
		var i, j, x;
		var hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
			"B", "C", "D", "E", "F"
		];
		var out = "";
		for(j = 0; j < inarray.length; ++j) {
			x = parseInt(inarray[j]) & 0xff;
			i = (x >> 4) & 0x0f;
			out += hex[i];
			i = x & 0x0f;
			out += hex[i];
		}
		var value = "";
		var outresult = "";
		for(var k = 0; k < out.length; k++) {
			if(out.charAt(k) != '0') {
				value = out.substr(k, out.length);
				outresult += value;
				break;
			}
		}
		return outresult;
	}
	// 在初始化plus api后在调用
	document.addEventListener('plusready', listenNFCStatus, false);

	var waiting;
	var readyWriteData = false;
	var readyRead = false;

	function writeData() {
		var textEle = document.getElementById('text');

		if(!textEle.value) {
			alert('请输入要写入的内容');
			return;
		}
		readyWriteData = true;
		waiting = plus.nativeUI.showWaiting("请将NFC标签靠近！");
	}
	// 扫描成功音频提示
	function audio_success(){
		document.getElementById("audio").play();
	}
</script>